package priv.utrix.micro.config;

import cn.hutool.core.util.StrUtil;
import org.redisson.Redisson;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * redisson配置文件
 *
 * @author utrix
 * @date 2020/12/9
 */
@Configuration
public class RedissonConfig {

    @Value("${spring.redis.host:localhost}")
    private String redisHost;
    @Value("${spring.redis.port:6379}")
    private String redisPort;
    @Value("${spring.redis.database:1}")
    private int redisDatabase;

    @Bean
    public Redisson redisson(){
        String redisAddress = StrUtil.strBuilder("redis://").append(redisHost).append(":").append(redisPort).toString();
        Config config = new Config();
        // 单机版
        config.useSingleServer().setAddress(redisAddress).setDatabase(redisDatabase);
        return (Redisson) Redisson.create(config);
    }

}
